package com.example.simple.work.service.impl;

import com.example.simple.work.entity.User;
import com.example.simple.work.mapper.UserMapper;
import com.example.simple.work.service.IUserService;
import com.example.simple.work.service.ex.UserIdNotExistException;
import com.example.simple.work.service.ex.UserPasswordErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public void login(User user) {
        // 获取用户输入的工号
        String userId = user.getUserId();
        // 获取用户输入的密码
        String userPassword = user.getUserPassword();
        System.out.println(userId);
        System.out.println(userPassword);
        // 查询工号是否存在
        User result = userMapper.findByUserId(userId);
        if(result == null){
            throw new UserIdNotExistException("员工工号不存在");
        }
        // 判断密码是否输入正确
        if(!result.getUserPassword().equals(userPassword) ){
            throw new UserPasswordErrorException("密码错误");
        }
    }
}
